/*
 * Copyright 2020-2021 redragon.dongbin
 *
 * This file is part of redragon-erp/赤龙ERP.

 * redragon-erp/赤龙ERP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.

 * redragon-erp/赤龙ERP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with redragon-erp/赤龙ERP.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.erp.inv.output.dao.model;

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import com.erp.masterdata.common.model.BaseModel;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
@Data
@MappedSuperclass
public class InvOutputLineBase extends BaseModel {

    //Constructors
    public InvOutputLineBase() {
    }
    
    //主键
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "output_line_id", unique = true, nullable = false)
    private Integer outputLineId;

    //出库行编码
//    @NotBlank(message="出库行编码不能为空")
    @Column(name = "output_line_code")
    private String outputLineCode;

    //出库头编码
    @Column(name = "output_head_code")
    private String outputHeadCode;

    //出库来源行编码（销售订单行编码）
    //@NotBlank(message="来源单据行编码不能为空")
    @Column(name = "output_source_line_code")
    private String outputSourceLineCode;

    //物料编码
//    @NotBlank(message="物料编码不能为空")
    @Column(name = "material_id")
    private String materialId;

    //物料编码
    @NotBlank(message="物料编码不能为空")
    @Column(name = "material_code")
    private String materialCode;

    @Column(name = "material_name")
    private String materialName;

    @Column(name = "category_name")
    private String categoryName;
    
    @Column(name = "brand")
    private String brand;

    //规格型号
    @Column(name = "standard")
    private String standard;

    //出库数量
    @NotNull(message="出库数量不能为空")
    @Column(name = "output_quantity", unique = false, nullable = false)
    private BigDecimal outputQuantity;

    //单价
    @Column(name = "price", unique = false, nullable = true)
    private BigDecimal price;
    
    public BigDecimal getPrice() {
        if(this.price!=null) {
            return this.price;
        }else if(this.getSoPrice()!=null){
            return this.getSoPrice();
        }
        
        return null;
    }

    
    //金额
    @Column(name = "amount", unique = false, nullable = true)
    private BigDecimal amount;
    
    public BigDecimal getAmount() {
        if(this.amount!=null) {
            return this.amount;
        }else if(this.getSoLineAmount()!=null){
            return this.getSoLineAmount();
        }
        
        return null;
    }

    
    //单位
    @Column(name = "unit", unique = false, nullable = true, length = 45)
    private String unit;
    
    public String getUnit() {
        if(StringUtils.isNotBlank(this.unit)) {
            return this.unit;
        }else if(StringUtils.isNotBlank(this.getSoUnit())) {
            return this.getSoUnit();
        }
        
        return null;
    }

    
    //备注
    @Column(name = "memo", unique = false, nullable = true, length = 200)
    private String memo;

    //版本
    @Column(name = "version", unique = false, nullable = false)
    private Integer version;

    //状态
    @Column(name = "status", unique = false, nullable = false, length = 10)
    private String status;


    
    /*
         * 用于显示的字段
     */
    @Transient
    private String materialStandard;
    @Transient
    private BigDecimal soPrice;
    @Transient
    private BigDecimal quantity;
    @Transient
    private BigDecimal outputedQuantity;
    @Transient
    private String soUnit;
    @Transient
    private BigDecimal soLineAmount;
    @Transient
    private String headOutputType;

}